/**
 * 
 */
package br.srv.full.virtual.postalServices.engine;

import java.util.Map;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceUnit;

import br.srv.full.persistence.BeansManagerException;
import br.srv.full.persistence.PersistBeansException;
import br.srv.full.persistence.RefreshBeansException;
import br.srv.full.persistence.UpdateBeansException;
import br.srv.full.persistence.utils.BeansManagerSupport;
import br.srv.full.virtual.bean.base.QueryID;
import br.srv.full.virtual.postalServices.base.PostalServicesBeansManager;
import br.srv.full.virtual.postalServices.base.PostalServicesBeansManagerLocal;

/**
 * @author Carlos Delfino
 * 
 */
@Stateless(mappedName = "PostalServicesBeansManager", name = "PostalSrvicesBeansManager")
public class PostalServicesBeansManagerEJB implements PostalServicesBeansManager, PostalServicesBeansManagerLocal {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9123521459961467949L;

	@PersistenceUnit(unitName = "VirtualPostalServicesUW")
	private EntityManager em;

	private BeansManagerSupport bms = new BeansManagerSupport();

	/**
	 * @param <bean>
	 * @param <key>
	 * @param p_class
	 * @param p__key
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class,
	 *      java.lang.Object)
	 */
	public <bean, key> bean find(Class<bean> p_class, key p__key) {
		return bms.find(em, p_class, p__key);
	}

	/**
	 * @param <bean>
	 * @param <params>
	 * @param p_class
	 * @param p__query
	 * @param p__params
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class,
	 *      br.srv.full.virtual.bean.base.QueryID, java.util.Map)
	 */
	public <bean, params> Object find(Class<bean> p_class, QueryID p__query, Map<String, Object> p__params) {
		return bms.find(em, p_class, p__query, p__params);
	}

	/**
	 * @param <bean>
	 * @param <params>
	 * @param p_class
	 * @param p__query
	 * @param p__params
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class,
	 *      br.srv.full.virtual.bean.base.QueryID, params[])
	 */
	public <bean, params> Object find(Class<bean> p_class, QueryID p__query, params... p__params) {
		return bms.find(em, p_class, p__query, p__params);
	}

	/**
	 * @param <bean>
	 * @param <params>
	 * @param p_class
	 * @param p__query
	 * @param p_fieldName
	 * @param p_params
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class,
	 *      br.srv.full.virtual.bean.base.QueryID, java.lang.String[], params[])
	 */
	public <bean, params> Object find(Class<bean> p_class, QueryID p__query, String[] p_fieldName, params[] p_params) {
		return bms.find(em, p_class, p__query, p_fieldName, p_params);
	}

	/**
	 * @param <bean>
	 * @param <params>
	 * @param p_class
	 * @param p__query
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class,
	 *      br.srv.full.virtual.bean.base.QueryID)
	 */
	public <bean, params> Object find(Class<bean> p_class, QueryID p__query) {
		return bms.find(em, p_class, p__query);
	}

	/**
	 * @param <bean>
	 * @param <params>
	 * @param p_class
	 * @param p__query
	 * @param p__params
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class,
	 *      java.lang.String, params[])
	 */
	public <bean, params> Object find(Class<bean> p_class, String p__query, params... p__params) {
		return bms.find(em, p_class, p__query, p__params);
	}

	/**
	 * @param <bean>
	 * @param p_class
	 * @return
	 * @see br.srv.full.persistence.BeansManager#find(java.lang.Class)
	 */
	public <bean> Object find(Class<bean> p_class) {
		return bms.find(em, p_class);
	}

	/**
	 * @param <bean>
	 * @param p_bean
	 * @param p_properties
	 * @return
	 * @throws PersistBeansException
	 * @throws BeansManagerException
	 * @see br.srv.full.persistence.BeansManager#persist(java.lang.Object,
	 *      java.lang.String[])
	 */
	public <bean> bean persist(bean p_bean, String... p_properties) throws PersistBeansException, BeansManagerException {
		return bms.persist(em, p_bean, p_properties);
	}

	/**
	 * @param <bean>
	 * @param p__bean
	 * @return
	 * @throws PersistBeansException
	 * @see br.srv.full.persistence.BeansManager#persist(java.lang.Object)
	 */
	public <bean> bean persist(bean p__bean) throws BeansManagerException {
		return bms.persist(em, p__bean);
	}

	/**
	 * @param <bean>
	 * @param p_bean
	 * @param p_properties
	 * @return
	 * @throws RefreshBeansException
	 * @see br.srv.full.persistence.BeansManager#refresh(java.lang.Object,
	 *      java.lang.String[])
	 */
	public <bean> bean refresh(bean p_bean, String... p_properties) throws RefreshBeansException {
		return bms.refresh(em, p_bean, p_properties);
	}

	/**
	 * @param <bean>
	 * @param p_bean
	 * @return
	 * @throws RefreshBeansException
	 * @see br.srv.full.persistence.BeansManager#refresh(java.lang.Object)
	 */
	public <bean> bean refresh(bean p_bean) throws RefreshBeansException {
		return bms.refresh(em, p_bean);
	}

	/**
	 * @param <bean>
	 * @param p_bean
	 * @param p_properties
	 * @return
	 * @throws UpdateBeansException
	 * @see br.srv.full.persistence.BeansManager#update(java.lang.Object,
	 *      java.lang.String[])
	 */
	public <bean> bean update(bean p_bean, String... p_properties) throws UpdateBeansException {
		return bms.update(em, p_bean, p_properties);
	}

	/**
	 * @param <bean>
	 * @param p_bean
	 * @return
	 * @throws UpdateBeansException
	 * @see br.srv.full.persistence.BeansManager#update(java.lang.Object)
	 */
	public <bean> bean update(bean p_bean) throws UpdateBeansException {
		return bms.update(em, p_bean);
	}
}
